import React from 'react';
import {Text, View} from "@tarojs/components";
import { AtRate } from 'taro-ui';

import './index.scss'

const rateTextMap=['非常差','差','一般','好','非常好']

const CommentRate=({value=0,onChange=()=>{},showText=false,showNum=false,children})=>{

  //获取评分文案
  const getText=()=>{
    const score=Math.ceil(value)
    if(score>0&&score<=5){
      return rateTextMap[score-1]
    }else{
      return ''
    }
  }

  return (
    <View className={showText?'event commentRate':'commentRate'}>
      {children&&<Text className="rateTitle">{children}</Text>}
      {showNum&&<Text className="rateText">{parseFloat(value).toFixed(1)}&nbsp;</Text>}
      <AtRate
        className="rateStar"
        value={Math.ceil(value)}
        onChange={onChange}
      />
      {showText&&<Text className="rateText">{getText()}</Text>}
    </View>
  )
}

export default CommentRate
